<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column
        prop="semesterName"
        label="入学学期"
        width="160"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="schoolName"
        label="校区"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="classAlias"
        label="班别"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="className"
        label="班名"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="trainingName"
        label="层次"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="majorsName"
        label="专业"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="建班日期"
        width="160"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="teacherName"
        label="主讲教师"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column prop="studentNum" label="注册学生" width="100">
        <template slot-scope="{ row }">
          <span>{{ row.studentNum || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="classAddr"
        label="线下教室"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column prop="totalCourseHours" label="总课时" width="100">
      </el-table-column>
      <el-table-column
        prop="courseStartDate"
        label="开课日期"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="courseStartWeeks"
        label="开课周"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="courseWeeksSection"
        label="周课节次"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="planEndWeeks"
        label="计划结课周"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column prop="isFinish" label="是否结课" width="100">
        <template slot-scope="scope">
          <span v-show="scope.row.isFinish == 1">是</span>
          <span v-show="scope.row.isFinish != 1">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="fees" label="报名费用" width="100">
      </el-table-column>
      <el-table-column label="操作" width="280" fixed="right">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              @click="handleStudentList(row)"
              >查看</el-button
            >
            <el-button
              type="primary"
              size="mini"
              :disabled="$button('752') == false ? true : false"
              @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button
              type="primary"
              size="mini"
              :disabled="$button('752') == false ? true : false"
              @click="handleAddStudent(row)"
              >添加学生</el-button
            >
            <el-button
              type="danger"
              size="mini"
              :disabled="$button('753') == false ? true : false"
              @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  eduTeachingQuery,
  eduTeachingDelete,
} from '@/api/admin/teach/eduTeaching.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
    Bus.$on('refreshClasGradeList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshClasGradeList')
  },
  methods: {
    getList() {
      eduTeachingQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //查看
    handleStudentList(row) {
      Bus.$emit('showDialogClasGradeView', row)
    },
    handleAddStudent(row) {
      Bus.$emit('showAddStudent', row)
    },

    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogClasGradeAdd', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduTeachingDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped>
.thumb {
  width: auto;
  height: 30px;
  cursor: pointer;
}
</style>